package com.ruoyi.project.wms.logistics.chuhuo.outgoods.controller;

import java.util.List;

import com.ruoyi.project.wms.outgoods.domain.WmsOutGoods;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.wms.logistics.chuhuo.outgoods.service.IChuWmsOutGoodsService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 【请填写功能名称】Controller
 * 
 * @author ruoyi
 * @date 2020-09-29
 */
@Controller
@RequestMapping("/chuhuo/outgoods")
public class ChuWmsOutGoodsController extends BaseController
{
    private String prefix = "wms/logistics/chuhuo/outgoods";
    @Autowired
    private IChuWmsOutGoodsService chuWmsOutGoodsService;

    @RequiresPermissions("system:goods:view")
    @GetMapping()
    public String goods()
    {
        return prefix + "/goods";
    }

    /**
     * 查询【所有出货单】列表
     */
    @RequiresPermissions("system:goods:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(WmsOutGoods wmsOutGoods)
    {
        startPage();
        List<WmsOutGoods> list = chuWmsOutGoodsService.selectWmsOutGoodsList(wmsOutGoods);
        return getDataTable(list);
    }

    /**
     * 导出【显示出货单】列表
     */
    @RequiresPermissions("system:goods:export")
    @Log(title = "【显示出货单】", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(WmsOutGoods wmsOutGoods)
    {
        List<WmsOutGoods> list = chuWmsOutGoodsService.selectWmsOutGoodsList(wmsOutGoods);
        ExcelUtil<WmsOutGoods> util = new ExcelUtil<WmsOutGoods>(WmsOutGoods.class);
        return util.exportExcel(list, "goods");
    }

    /**
     * 新增【新增出货单】
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存【新增出货单】
     */
    @RequiresPermissions("system:goods:add")
    @Log(title = "【新增出货单】", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(WmsOutGoods wmsOutGoods)
    {
        return toAjax(chuWmsOutGoodsService.insertWmsOutGoods(wmsOutGoods));
    }

    /**
     * 修改【修改出货单】
     */
    @GetMapping("/edit/{ogid}")
    public String edit(@PathVariable("ogid") Long ogid, ModelMap mmap)
    {
        WmsOutGoods wmsOutGoods = chuWmsOutGoodsService.selectWmsOutGoodsById(ogid);
        mmap.put("wmsOutGoods", wmsOutGoods);
        return prefix + "/edit";
    }

    /**   /logistics/orderManager/  logistics:orderManager:view
     * 修改保存【修改出货单】
     */
    @RequiresPermissions("system:goods:edit")
    @Log(title = "【修改出货单】", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(WmsOutGoods wmsOutGoods)
    {
        return toAjax(chuWmsOutGoodsService.updateWmsOutGoods(wmsOutGoods));
    }

    /**
     * 删除【删除出货单】
     */
    @RequiresPermissions("system:goods:remove")
    @Log(title = "【删除出货单】", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(chuWmsOutGoodsService.deleteWmsOutGoodsByIds(ids));
    }
}
